/*
舊架構的程式碼尚未清除乾淨！
*/
package idv.jieh.web;

import java.io.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;

public class ViewBean implements Serializable {

  private static final long serialVersionUID = 6904970847878797829L;

  private String packagePath;
  private String funcID;
  private String page;
  private String jspFullPath;

  public ViewBean() {
  }

  // 程式開發架構四代
  public String getJspFullPath(){
    return jspFullPath;
  }

  public ViewBean(Object obj, Object page) {
    // 程式開發架構四代
    if(page != null){
      jspFullPath = obj.toString() + page.toString() + ".jsp";
      this.page = page.toString();
    }else{
      this.page = null;
    }

    // 程式開發架構一代
//    Class obj_class = obj.getClass();
//    packagePath = obj_class.getPackage().getName();
//
//    String class_name = obj_class.getSimpleName();
//    funcID = class_name.substring(0, class_name.length() - 4);
  }

  // 程式開發架構四代
  private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    ois.defaultReadObject();
  }

  // 程式開發架構四代
  private void writeObject(ObjectOutputStream oos) throws IOException {
    oos.defaultWriteObject();
  }

  /**
   * 取得客製化的操作畫面物件<p>
   * 此方法主要是給 View.jsp 專用的，這個方法會根據藉由此物件其他方法輸入的資訊...
   * @return ViewBody
   */
  public ViewBody getViewBody(){
    ViewBody r = null;
    String name = getClassName();
    try{
      r = (ViewBody)Class.forName(name).newInstance();
    }catch(Exception e){
      e.printStackTrace();
    }
    return r;
  }

  // 程式開發架構四代
  public ActionForward forward(HttpServletRequest request, ActionMapping mapping){
    if(page == null) return null;
    setAttribute(request);
    return mapping.findForward("VIEWBEAN_JSP");
  }

  // 程式開發架構四代
  /**
   * 此方法會將自己本身這個物件放到 request scope。
   * @param request HttpServletRequest
   */
  public void setAttribute(HttpServletRequest request){
    request.setAttribute(Constant.VIEWBEAN_KEY, this);
  }

  public String getPageID(){
    return funcID + page;
  }

  public String getClassName(){
    return packagePath + "." + funcID + "View";
  }

  public void setPage(String page) {
    this.page = page;
  }

  public void setFuncID(String funcID) {
    this.funcID = funcID;
  }

  public void setPackagePath(String packagePath) {
    this.packagePath = packagePath;
  }

  public String getPackagePath() {
    return packagePath;
  }

  public String getFuncID() {
    return funcID;
  }

  public String getPage() {
    return page;
  }

} // end class ViewBean
